﻿@using System.Xml.Linq

<ul class="unit-list activity latest">
@if(String.IsNullOrWhiteSpace(Model.Error))
{
    var xReport = Model.Data as XElement;
    var xEntries = xReport.Elements("entry");
    if(xEntries.Any())
    {
        foreach(var i in xEntries)
        {
            string type = i.Attribute("Type").Value;
            var date = DateTime.FromBinary(i.Attribute("Date").Value.ParseAs<Int64>());
            int entityID = i.Attribute("EntityID").Value.ParseAs<Int32>();
            string title = i.Attribute("Title").Value;
            string description = i.Attribute("Description").Value;
            <li class="unit activity @type.ToLowerInvariant()">
                <span>@Svc.DateTimeRel(date)</span>
                @if(type == "ForumTopic")
                {
                    description = BBCodeHelper.StripTags(description);
                    description = HtmlUtility.FromPlainText(description);
                    <a href="@Url.Action(Loc.Act("Show").Ctrl("Topic").Area("Forum").Set(new
                    {
                        id = entityID
                    }).Localized())">@title</a>
                }
                else if(type == "ForumPost")
                {
                    description = BBCodeHelper.StripTags(description);
                    description = HtmlUtility.FromPlainText(description);
                    <a href="@Url.Action(Loc.Act("Show").Ctrl("Topic").Area("Forum").Set(new
                    {
                        id = entityID
                    }).Localized())">@T(Res.In("Common").Of("Expr").Name("Re"), title)</a>
                }
                else if(type == "Publication_BlogPost")
                {
                    description = HtmlUtility.FromPlainText(description);
                    <a href="@Url.Action(Loc.Act("Show").Ctrl("Post").Area("Blog").Set(new
                    {
                        id = entityID
                    }).Localized())">@title</a>
                }
                else if(type == "Publication_Article")
                {
                    description = HtmlUtility.FromPlainText(description);
                    <a href="@Url.Action(Loc.Act("Show").Ctrl("Article").NoArea().Set(new
                    {
                        id = entityID
                    }).Localized())">@title</a>
                }
                else if(type == "Publication_News")
                {
                    description = HtmlUtility.FromPlainText(description);
                    <a href="@Url.Action(Loc.Act("Show").Ctrl("News").NoArea().Set(new
                    {
                        id = entityID
                    }).Localized())">@title</a>
                }
                @if(!String.IsNullOrWhiteSpace(description))
                {
                    <p>@Html.Raw(description)</p>
                }
            </li>
        }
    }
    else
    {
        <li class="empty"><span>@T(Res.In("Common").Of("Expr").Name("NoData"))</span></li>
    }
}
else
{
    <li class="error">@Model.Error</li>
}
</ul>
